package cn.gailvlun.gll.presentation.xroom.adapter

import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.widget.TextView
import cn.gailvlun.gll.R
import cn.gailvlun.gll.widget.OnCancelListener
import cn.gailvlun.gll.widget.OnConfirmListener
import kotlinx.android.synthetic.main.dialog_bottom.*

abstract class BottomDialog<DATA>: BaseDialog {

    constructor(context: Context?) : super(context)

    protected var tvPositive: TextView? = null
    protected var tvNegative: TextView? = null

    var onConfirmListener: OnConfirmListener<DATA>? = null
    var onCancelListener: OnCancelListener<DATA>? = null

    private var data: DATA? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContentView(R.layout.dialog_bottom)
        LayoutInflater.from(context).inflate(getResourceId(), top_container, true)

        tvPositive = findViewById(R.id.tv_positive)
        tvNegative = findViewById(R.id.tv_negative)

        tvPositive?.setOnClickListener {
            onConfirmListener?.onConfirm(this@BottomDialog, data)
        }
        tvNegative?.setOnClickListener {
            onCancelListener?.onCancel(this@BottomDialog, data)
        }
    }

    abstract fun getResourceId(): Int

}